from rest_framework import serializers
from .models import SPU,Good
class SpuSer(serializers.ModelSerializer):
    brand_name = serializers.SerializerMethodField(read_only=True)
    def get_brand_name(self,obj):
        return obj.brand.name
    class Meta:
        model = SPU
        fields = '__all__'

class GoodSer(serializers.ModelSerializer):
    cate_name = serializers.SerializerMethodField(read_only=True)
    spu_name = serializers.SerializerMethodField(read_only=True)
    def get_cate_name(self,obj):
        return obj.cate.name
    def get_spu_name(self,obj):
        return obj.spu.name
    class Meta:
        model = Good
        fields = '__all__'